﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace AdvancedProgramming
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnSelectFile1_Click(object sender, EventArgs e)
        {
            txtFile1.Text = SelectFile();
        }

        private void btnSelectFile2_Click(object sender, EventArgs e)
        {
            txtFile2.Text = SelectFile();
        }

        private string SelectFile()
        {
            string fileName = "";

            OpenFileDialog fdlg =  new OpenFileDialog();
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                fileName = fdlg.FileName;
            }

            return fileName;
        }

        private void btnCompare_Click(object sender, EventArgs e)
        {
            if (dlAlgorithm.Text == "Transform 1")
            {
                Transform1 ts = new Transform1();
                List<string> result = ts.Compare(txtFile1.Text, txtFile2.Text);
                
                string output = "";
                foreach(string s in result)
                {
                    output += s + System.Environment.NewLine;
                }
                output += "------------------------------------------";
 
                output += "Edit aangeroepen: " + ts.EditCounter + System.Environment.NewLine;
                output += "Cost: " + ts.CostCounter + System.Environment.NewLine;
 
                rtfOutput.Text = output;
            }
            else if (dlAlgorithm.Text == "Transform 2")
            {
                Transform2 ts = new Transform2();
                //rtfOutput.Text = ts.Compare(txtFile1.Text, txtFile2.Text);
                string str = ts.Compare(txtFile1.Text, txtFile2.Text);
                WriteStringToFile(str);

            }
        }

        private void WriteStringToFile(string str)
        {
            File.WriteAllText("distance.html", str);

        }
    }
}
